package com.haikesi.api.syslog.service.impl;

import com.haikesi.api.base.Type;
import com.haikesi.api.syslog.dao.SysLogDao;
import com.haikesi.api.syslog.domain.po.SysLogPO;
import com.haikesi.api.syslog.domain.vo.SysLogSaveVO;
import com.haikesi.api.syslog.domain.vo.SysLogSearchVO;
import com.haikesi.api.syslog.domain.vo.SysLogVO;
import com.haikesi.api.syslog.service.ISysLogService;
import com.haikesi.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName SysLogServiceImpl
 * @Author HandsomeBugs
 * @Date 2019/4/25 14:24
 * @Version 1.0
 **/

@Service
@Transactional
public class SysLogServiceImpl implements ISysLogService {
    @Autowired
    private SysLogDao sysLogDao;

    @Override
    public List<SysLogVO> getList(SysLogSearchVO searchVO) {
        return sysLogDao.getList(searchVO);
    }

    @Override
    public void create(SysLogSaveVO saveVO) {
        SysLogPO po =new SysLogPO();
        BeanUtils.copyProperties(saveVO, po);
        po.preInsert();
        if(StringUtils.isBlank(po.getCreateBy())){
            po.setCreateBy(saveVO.getUserId());
            po.setUpdateBy(saveVO.getUserId());
        }
        int i = sysLogDao.insertSelective(po);
        if (i == 0) {
            new BusinessException(Type.EXCEPTION_FAIL);
        }
    }
}
